import os
from utils import date_util, doc_util, k_util, excel_util, json_util, form_util, read_config
from service.data_service import stock_dict

result_path = os.path.join(read_config.data_path, 'result')
document_path = os.path.join(read_config.data_path, 'common', 'config')
today_str = date_util.get_format_date_str("%Y-%m-%d")
base_result_path = os.path.join(result_path, '厂字形态', today_str)

if not os.path.exists(base_result_path):
    os.makedirs(base_result_path)  # 没有创建文件夹


# 开启监控定时任务
def monitor_all_indicators():
    print('开始监控')
    content_arr = [['编码', '名称', '得分', '形态']]
    stock_list = doc_util.get_path_doc_info(os.path.join(document_path, '10.板块前五'))
    for stock_info in stock_list:
        stock_info = json_util.info_to_json(stock_info)
        code = stock_info['code']
        name = stock_info['name']
        if code not in stock_dict.keys():
            print(str(stock_info) + '****&&&&&&&&&&&&&&&&&')
            continue
        day_ks = k_util.day_k_local(code, 10)
        x = form_util.gen_x(day_ks, 'sp')
        x.reverse()
        score = form_util.judge_form_expect(x, '厂')
        if score == 0:
            print(stock_info)
            continue
        content_arr.append([code, name, score, '厂'])
    excel_util.gen_an_excel(base_result_path, '厂字形态', '', content_arr)


if __name__ == '__main__':
    monitor_all_indicators()
